<template>
    <div class="save-wrapper ui container" v-if="show">
        <div class="ui very relaxed  grid">
            <div class="sixteen wide column">

                <form action="" class="ui form" @submit.prevent="submit_confirm">
                    <div class="ui header">{{titleType}}显示形式数据源</div>

                    <div class="fluid field">
                        <label for="">名称</label>
                        <input type="text" v-model="vo.title" name="title" placeholder="请输入名称">
                    </div>

                    <div v-if="pdata" class="fluid field">
                        <label for="">模型</label>
                        <fselect :fname="bindModelinfo.name" @selectValsChange='selectEvent' :val="vo.bindModel"
                                 :data="pdata"
                                 placeholder="请选择绑定模型"></fselect>
                    </div>

                    <!--<myenum :param="{}" v-if="enumField.fval!==undefined" :field="enumField"-->
                            <!--@setVo='setEnum'></myenum>-->
                    <myenum :param="{}" v-if="enumField_data_type.fval!==undefined"
                            :field="enumField_data_type" @setVo='setEnum'></myenum>

                    <div class="fluid field">
                        <label for="">参数</label>
                        <input type="text" v-model="vo.bind_param" name="bind_param" placeholder="请输入绑定模型参数">
                    </div>
                    <div class="fluid field">
                        <label for="">名称字段</label>
                        <input type="text" v-model="vo.bind_name_field" name="bind_name_field"
                               placeholder="请输入绑定字段名称字段">
                    </div>
                    <myenum :param="{}" v-if="enumField_need_get_bind_name.fval!==undefined"
                            :field="enumField_need_get_bind_name" @setVo='setEnum'></myenum>


                    <p class="submitRow">
                        <button type="submit" class="ui button">提 交</button>
                    </p>
                </form>


            </div>
        </div>
    </div>
</template>
<script type="text/ecmascript-6">
    import fselect from 'components/form/select'
    import myenum from 'components/field/enum';

    import tool from 'src/util/tool';
    import util from '_util/index';
    import logic from '_logic';
    import {
        mapState,
        mapMutations,
        mapGetters,
        mapActions
    } from 'vuex'

    const store = util.store

    export default {
        data() {
            return {
                result: '',
                url: '',
                val: '',
                vo: null,
                bindNames: null,
                field: {
                    bind_name_field: 'title',
                    need_get_bind_name: 1
                },
                loading: false,
                page: 1,
                total: 0,
                pdata: null,
                type: 'add',
                model: {},
                enumField: {
                    name: 'bind_type',
                    title: '类型',
                    enum_type: 1,
                    enum_val: [
                        '单选', '多选'
                    ]
                },
                enumField_need_get_bind_name: {
                    name: 'need_get_bind_name',
                    title: '是否需要获取名称',
                    enum_type: 1,
                    enum_val: [
                        '否', '是'
                    ]
                },
                enumField_data_type: {
                    name: 'data_type',
                    title: '数据类型',
                    enum_type: 1,
                    enum_val: [
                        'json', '"|"分隔'
                    ]
                },

                typeData: null,
                bindModelinfo: {
                    title: '绑定模型',
                    name: 'bindModel'
                },
                lines: {},
                param: {},
                tabs: [],
                result_type: 'rs_error',
                curIndex: '1',
                show: true
            }
        },
        methods: {
            setEnum(name, val) {
                this.vo[name] = val;
            },

            selectEvent(val, fname) {
                if (fname == 'mid') {
                    this.mid = val || 0
                }
                this.vo[fname] = val

            },
            getData(url, param) {
                util.http.SR(this, url, param, null, (rs) => {
                    this.lines = rs.lines
                    this.total = rs.total

                    this.loading = false
                });
            },
            submit_confirm() {
                util.showConfirm(this, () => {
                    this.onSubmit()
                }, {content: '确认提交吗？'});
            },
            onSubmit() {
                let op = this.$store.state.global.op || 'insert';
                let url = tool.getApi(this, 'Bindconf', op);

                util.http.SR(this, url, this.vo, '操作成功', () => {
                    let eventVue = util.store.get(this,'eventVue');
                    eventVue.$emit('afterAdd')
                });

            },
            getPdata() {
                let param = {
                    notParse: 1
                }
                util.data.get(this, 'Model', param, (rs) => {
                    this.pdata = rs
                });
            },
        },
        watch: {
            vo: function (val, old) {
                if (val != old) {
                }
            }
        },
        computed: {
            showDataType() {
                return this.vo.bind_type == 1;
            },
            titleType() {
                return logic.edit.get_titleType(this);
            },
            ctl() {
                return this.$route.query.ctl;
            },

        },
        components: {
            fselect,
            myenum
        },
        props: [],
        mounted() {
        },

        destroyed() {


        },
        created() {
            this.vo = store.get(this, 'editVo')
            this.getPdata()

            this.enumField.fval = this.vo['bind_type'] || 0;
            this.enumField_data_type.fval = this.vo['data_type'] || 1;
            this.enumField_need_get_bind_name.fval = this.vo['need_get_bind_name'] || 0;


        }
    }
</script>
<style rel="stylesheet/less" scoped lang="less">@import "../../common/style/mixin";

@dir: "edit/";
form {
    .submitBtn();
}
</style>
